<?php
/**
 * DESC:
 * 作者:晨光
 * EMAIL:461718846@qq.com
 * DATE:2020/5/11
 */

namespace app\admin\controller;


use app\common\controller\AdminUserBase;
use think\facade\Request;

class Carousel extends AdminUserBase
{
    public function index(){
        if (Request::isAjax()){
            $param = input();
            $where = [];
            if (!empty($param['cate_id'])){
                $where[] = ['cate_id','=',$param['cate_id']];
            }
            $data = \app\common\model\Carousel::with(['dictionaryItem'])->where($where)->select();
            $this->result($data);
        }
        return view();
    }
    public function form(){
        $id = input('id');
        $data = \app\common\model\Carousel::get($id);
        $this->assign('data',$data);
        return view();
    }
    public function carousel_save(){
        $param = input();
        $carouselModel = new \app\common\model\Carousel();

        if (empty($param['id'])){
            $param['admin_id'] = session('admin.id');
            $res = $carouselModel->allowField(true)->isUpdate(false)->save($param);
            saveAdminLog("添加轮播");
        }else{
            $res = $carouselModel->allowField(true)->isUpdate(true)->save($param,['id'=>$param['id']]);
            saveAdminLog("编辑轮播");
        }

        if ($res !== false){
            $this->success();
        }else{
            $this->error();
        }
    }
    public function carousel_del(){
        $id = input('id');
        $res = \app\common\model\Carousel::destroy($id);
        if ($res !== false){
            saveAdminLog("删除轮播");
            $this->success();
        }else{
            $this->error();
        }
    }
}
